package com.candy.filter;


import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

//使用注解方式进行配置，配置请求的路径，该配置表示所有的请求都经过该过滤器
@WebFilter("/*")
public class EncodingFilter implements Filter {
//    处理具体的业务逻辑
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        chain.doFilter(request,response);
    }
//会在过滤器初始化的时候会被调用
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }
//在过滤器销毁的时候调用
    @Override
    public void destroy() {
        Filter.super.destroy();
    }
}
